<template>
  <div>
    <article class="innerPage bookList">
      <header class="breadcrumb">
        <x-breadcrumb :path="$route.path" :title="$route.meta.breadcrumb" :startIndex="$route.meta.startIndex">
        </x-breadcrumb>
      </header>
      <section>
        <vmform class="act-form" @btn_submit="btn_submit" type="chang" :fromData="fromData" @cancel="$router.back()" :cropImg="cropImg" :cropImgOne="cropImgOne"></vmform>
      </section>
    </article>
  </div>
</template>

<script>
import vmform from "../components/form.vue";
export default {
  components: {
    vmform,
  },
  props: {},
  data() {
    return {
      cropImg: "cropImgOne1",
      cropImgOne: "cropImgfen1",
      fromData: {
        title: "",
        img: "",
        intro: "",
        start_time: "",
        end_time: "",
        head_cavity_id: "",
      },
    };
  },
  computed: {},
  watch: {},
  activated() {
    this.getinfo();
    this.setPageTabs();
    if (this.$route.query.action) {
      if (this.$route.query.action != "refresh") {
        this.fromData = this.$options.data().fromData;
        this.getinfo();
      }
    } else {
      this.fromData = this.$options.data().fromData;
      this.getinfo();
    }
  },
  mounted() { },
  methods: {
    // 获取详情
    async getinfo() {
      try {
        let res = await this.request({
          url: "/admin/resourceVideoManage/detail",
          method: "get",
          loading: true,
          data: {
            guid: this.$route.query.id,
          },
        });
        if (res) {
          this.fromData = {
            guid: this.$route.query.id,
            title: res.content.title,
            author: res.content.author,
            type_id: res.content.type_id,
            img: res.content.img,
            pre_time: res.content.pre_time,
            press: res.content.press,
            // isbn: res.content.isbn,
            intro: res.content.intro,
          };
        }
      } catch (err) {
        this.errorHandler(err);
      }
    },
    // fromData数据处理
    async btn_submit(e) {
      this.postList();
    },
    // 修改请求
    async postList() {
      try {
        let res = await this.request({
          url: "/admin/resourceVideoManage/change",
          method: "post",
          loading: true,
          data: {
            ...this.fromData,
          },
        });
        if (res) {
          let that = this;
          this.$message.success({ message: "修改成功", offset: 500 });
          setTimeout(() => {
            // this.$router.go(-1)
            that.pageTurnParams("videoManageList", { action: "refresh" });
          }, 2000);
        }
      } catch (err) {
        this.errorHandler(err);
      }
    },
  },
};
</script>
<style lang="scss" scoped></style>
